﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ItemView : System.Web.UI.Page
{
    private DataTable GetProducts()
    {
        // Load dữ liệu cho combobox, DB Northwin, Table Categories
        // dùng DataTable
        DataTable productTable = new DataTable();

        using (SqlConnection sqlConnection = new SqlConnection())
        {
            sqlConnection.ConnectionString =
                "Data Source=dell-n5110;Initial Catalog=Northwind; Integrated Security=true;";

            sqlConnection.Open();

            SqlCommand selectCommand = new SqlCommand("SELECT * FROM Products",
                                                      sqlConnection);
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);

            sqlDataAdapter.Fill(productTable);
        }

        return productTable;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        DetailsView1.DataSource = GetProducts();
        DetailsView1.DataBind();
    }

    protected void DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e)
    {
        DetailsView1.ChangeMode(e.NewMode);
        DetailsView1.DataSource = GetProducts();
        DetailsView1.DataBind();
    }
}